<?php
/**
 * Created by PhpStorm.
 * User: 86158
 * Date: 2021/6/22
 * Time: 15:04
 */

namespace App\Services\user;


use App\Models\user\Depart;

class DepartService
{
    public static function getBranch($type = 1,$sort = 0,$pre = ''):array
    {
        $array =  Depart::select('id','name','pid')
            ->where('type',$type)
            ->where('pid','!=',0)
            ->get()
            ->toArray();

        foreach ($array as $k => $v){
            $array[$k]['name'] =  $pre.$v['name'];
        }

        $array = array_pluck($array, 'name','id');

        if ($sort){
            $array = array_exchange($array,key($array),$sort);
        }
        return $array;
    }
}